<template>
    <basic-container>
      <div style="width:100%;min-height: 50px;padding-left:5px;display: inline-block;">
        <el-container>
          <el-container>
            <el-aside width="150px">
              <el-button type="primary" @click="saveLine" style="float: left;">保存</el-button>
              <el-button type="primary" @click="handlePrint" style="float: left;">打印</el-button>
            </el-aside>
            <el-container>
              <el-main style="background: #fff!important">
                <div v-for="arr in logList" style="width:120px;margin-left: 10px;min-height: 20px;font-size: 12px;float: left;">
                  <span>{{arr.operator}}</span>
                  <br/>
                  <span style="width:100px">{{arr.time}}</span>
                </div>
              </el-main>
            </el-container>
          </el-container>
        </el-container>
      </div>
      <template>
        <div id="printDetail">
          <br/>
          <div class="pull-auto"  style="text-align: left;font-size: 16px;color:#3478f5">
            <div class="block">
              产线名称：{{realityLineName}}<i class="el-breadcrumb__separator el-icon-arrow-right"></i>品号：{{articleNumber}} <i class="el-breadcrumb__separator el-icon-arrow-right"></i>产品工艺名称：{{productProcessName}}<i class="el-breadcrumb__separator el-icon-arrow-right"></i>产品类型： {{productLineType}}</div>
          </div>
          <br/>
          <el-container>
            <el-main class="demo">
                <avue-flow :height="800"
                                  width="100%"
                                  ref="flow"
                                  :option="option"
                                  v-model="flowForm">
                <template #header="{node}" >
                  {{(node || {}).name}}
                </template>
                <template slot-scope="{node}">
                  <el-descriptions  class="margin-top"  title="工序属性" :column="1" size="small" border >
                    <el-descriptions-item label="工段">
                      <avue-select   v-model="form[node.id+`_workshopSection`]" filterable clearable  dialogWidth="100%"   placeholder="请选择工段"  :props="{label: 'label',value: 'value'}"  :dic="workshopSectionList" ></avue-select>
                    </el-descriptions-item>

                    <el-descriptions-item label="设备">
                      <deviceSelect   :ref="node.id+`_devicePage`"
                                      v-model="form[node.id+`_device`]"
                                      attributeName="设备"
                                      attributeField="device"
                                      :deviceClass="form[node.id+`_deviceClass`]"
                                      :nodeId = "node.id"
                                      :seleteOptions="deviceList"
                                      :defaultVal ="form[node.id+`_device`]"
                                      @handleSelectData = "handleSelectData"/>
                      <div element-loading-text="拼命加载中"  element-loading-spinner="el-icon-loading" v-loading="deviceList.length==0"></div>
                    </el-descriptions-item>

                    <el-descriptions-item label="工具">
                      <deviceSelect   :ref="node.id+`_toolPage`"
                                      v-model="form[node.id+`_tool`]"
                                      attributeName="工具"
                                      attributeField="tool"
                                      :deviceClass="form[node.id+`_deviceClass`]"
                                      :nodeId = "node.id"
                                      :seleteOptions="toolList"
                                      :defaultVal ="form[node.id+`_tool`]"
                                      @handleSelectData = "handleSelectData"/>
                      <div element-loading-text="拼命加载中"  element-loading-spinner="el-icon-loading" v-loading="toolList.length==0"></div>
                    </el-descriptions-item>

                    <el-descriptions-item label="夹具">
                      <deviceSelect   :ref="node.id+`_clampPage`"
                                      v-model="form[node.id+`_clamp`]"
                                      attributeName="夹具"
                                      attributeField="clamp"
                                      :deviceClass="form[node.id+`_deviceClass`]"
                                      :nodeId = "node.id"
                                      :seleteOptions="clampList"
                                      :defaultVal ="form[node.id+`_clamp`]"
                                      @handleSelectData = "handleSelectData"/>
                      <div element-loading-text="拼命加载中"  element-loading-spinner="el-icon-loading" v-loading="clampList.length==0"></div>
                    </el-descriptions-item>

                    <el-descriptions-item label="物料">
                      <avue-select   v-model="form[node.id+`_material`]" filterable clearable  dialogWidth="100%"  multiple placeholder="请选择物料"  :props="{label: 'materialName',value: 'id'}"  :dic="materialDataList" ></avue-select>
                    </el-descriptions-item>

                    <el-descriptions-item label="辅料">
                      <avue-select   v-model="form[node.id+`_auxiliaryMaterial`]" filterable clearable  dialogWidth="100%"  multiple placeholder="请选择辅料"  :props="{label: 'materialName',value: 'id'}"  :dic="auxiliaryMaterialList" ></avue-select>
                    </el-descriptions-item>

                    <el-descriptions-item label="设备分类">
                      <avue-select   v-model="form[node.id+`_deviceClass`]" filterable clearable   dialogWidth="100%"  multiple placeholder="请选择设备分类"  :props="{label: 'label',value: 'value'}"  :dic="deviceClassList" @change="deviceClassChange(node.id)"></avue-select>
                    </el-descriptions-item>

                    <el-descriptions-item label="作业指导书">
                      <el-upload
                        class="avatar-uploader"
                        accept="application/pdf"
                        list-type="text"
                        action="#"
                        :file-list="form[node.id+`_workingBookFileList`]"
                        :show-file-list="false"
                        :http-request="(file)=>{uploadFile(file, node.id)}"
                        :auto-upload="false"
                        :before-remove="(file, file_list)=>{beforeRemove(file, file_list, node.id)}"
                        :on-change="(file, file_list)=>{workingBookChange(file, file_list, node.id)}"
                        :limit="2">
                        <el-button size="mini" type="primary" plain>选择作业指导书</el-button>
                      </el-upload>
                      <div  style="float: left;">
                        <a target="_blank" :href="form[node.id+`_workingBookFileListPDF`]">{{form[node.id+`_workingBookFileListPDFName`]}}</a><i class="el-icon-delete" style="cursor:pointer;margin-left: 2px" v-if="form[node.id+`_workingBookFileListPDF`]!='#' "@click="deleteWorkingBook(node.id)" ></i>
                      </div>
                    </el-descriptions-item>

                  </el-descriptions>
                </template>
              </avue-flow>

            </el-main>
          </el-container>
        </div>
      </template>
    </basic-container>
</template>

<script>
    import {updateRealityProdictLine,getRealityProductLineDetailsList} from '@/api/pfoc/realityproductline'
    import { uploadSubmit,deletWorkBook,getRealityLineDetails } from '@/api/pfoc/realityproductlinedetails'
    import { getObj} from '@/api/pfoc/factorysettings'//获取当前工厂信息
    import { getDevice,getDeviceClassList} from '@/api/hengdong/pfocinterface'//获取设备相关
    import { getMaterialAccessoryLibraryList } from '@/api/pfoc/materialaccessorylibrary'  //获取0:物料;1:辅料;
    import { getLogList} from '@/api/pfoc/productlinelog'
    import { tableOption } from '@/const/crud/pfoc/realityproductlinedetails'
    /**引入设备下拉框*/
    import deviceSelect from '@/views/pfoc/realityproductline/custom-select'
    export default {
        name: "edit-reality-line",
        components: {
            //设备下拉框
            deviceSelect,
        },
        props:{
            lineId:{
                type:String
            },
            productLineTypeList:{//产品类型集合
                type:Array
            },
            workshopSectionList:{//工段集合
                type:Array
            },
        },
        data() {
            return {
                count: 0,
                nodeCount:0,//节点下标
                form: [],//提交时数据集合
                flowForm:'',
                processAttributeList:[],//工序通用属性集合
                processAttributeDataList:[],//工序通用属性数据集合
                deviceClassList:[],//设备分类集合
                articleNumber:null,//品号
                productProcessName:null,//产品工艺名称
                organizationId:null,//组织ID
                organizationName:null,//组织名称
                realityLineMainData:{},//真实产线主数据
                realityLineSubData:[],//真实产线详情数据
                realityLineDeviceConfigListDeleteIds:[],//实际产线设备配置需要删除的ID集合
                realityLineName:null,//真实产线名称
                tableLoading: false,
                tableOption: tableOption,
                option: {
                    name: null,
                    nodeList: [],//工序节点集合
                    lineList: [],//工序各节点指向顺序集合
                },
                fileData: new FormData(),
                loading:false,
                id: null,
                logList:[],//操作日志集合
                productLineType:null,//产品类型
                deviceList:[],//设备集合
                clampList:[],//夹具集合
                toolList:[],//工具集合
                materialDataList:[],//物料集合
                auxiliaryMaterialList:[],//辅料集合
                workList:[],//作业指导书集合
                productProcessId:null,//产品工艺ID

            };
        },
        created() {
            //获取当前产线日志
            this.getLogListData();
            //获取当前工厂信息
            this.getFactoryInfo();
            //获取物料集合
            this.getMaterialDataLists();
            //获取辅料集合
            this.getAuxiliaryMaterialLists();
            //获取设备分类数据
            this.getDeviceClassListData();
        },
        computed: {
            nodeList () {
                return this.option.nodeList
            }

        },
        mounted() {
        },
        methods: {
            getRealityProductLineDetails(){
                if(!this.validatenull(this.lineId)) {
                    this.tableLoading = true
                    getRealityProductLineDetailsList(this.lineId).then(response => {
                        this.$refs.flow.resetPlumb();
                        var data =response.data.data;
                        //获取实际产线主表数据
                        this.realityLineMainData= data.realityProductLine;//实际产线主数据
                        //获取实际产线子表数据
                        this.realityLineSubData = data.realityProductLineDetailsList;//实际产线子表数据
                        //实际产线设备配置需要删除的ID集合
                        this.realityLineDeviceConfigListDeleteIds=data.realityLineDeviceConfigListDeleteIds;
                        //品号
                        this.articleNumber=this.realityLineMainData.articleNumber;
                        //产品工艺名称
                        this.productProcessName=this.realityLineMainData.productProcessName;
                        //实际产线名称
                        this.realityLineName =this.realityLineMainData.realityLineName;
                        //产品工艺ID
                        this.productProcessId = this.realityLineMainData.productProcessId;
                        this.productLineType=this.realityLineMainData.productLineType;//产品类型
                        //设置反显工序
                        this.option.nodeList = JSON.parse(this.realityLineMainData.processNodes);
                        //设置反显工序指向顺序
                        this.option.lineList =  JSON.parse(this.realityLineMainData.processNodeLine);
                        //初始化节点下标
                        var n =  this.option.nodeList[ this.option.nodeList.length-1].id;
                        this.nodeCount = parseInt(n.split("node")[1])+1;

                        //注册动态节点变量
                        for(var n=0;n<this.realityLineSubData.length;n++) {
                            var  nodeId = this.realityLineSubData[n].nodeId;

                            if(this.validatenull(this.realityLineSubData[n].workshopSection)){
                                this.$set(this.form, nodeId+ "_workshopSection", null);//注册动态节点-工段
                            }else {
                                this.$set(this.form, nodeId + "_workshopSection", this.realityLineSubData[n].workshopSection);//注册动态节点-工段
                            }

                            if(this.validatenull(this.realityLineSubData[n].device)){
                                this.$set(this.form, nodeId+ "_device", this.realityLineSubData[n].device);//注册动态节点-设备
                            }else {
                                this.$set(this.form, nodeId + "_device", this.realityLineSubData[n].device.split(","));//注册动态节点-设备
                            }
                            if(this.validatenull(this.realityLineSubData[n].tool)){
                                this.$set(this.form, nodeId+ "_tool", this.realityLineSubData[n].tool);//注册动态节点-工具
                            }else {
                                this.$set(this.form, nodeId + "_tool", this.realityLineSubData[n].tool.split(","));//注册动态节点-工具
                            }
                            if(this.validatenull(this.realityLineSubData[n].clamp)){
                                this.$set(this.form, nodeId+ "_clamp", this.realityLineSubData[n].clamp);//注册动态节点-夹具
                            }else {
                                this.$set(this.form, nodeId + "_clamp", this.realityLineSubData[n].clamp.split(","));//注册动态节点-夹具
                            }
                            var deviceNameStr = this.realityLineSubData[n].deviceNames;
                            this.$set(this.form, nodeId + "_deviceName",deviceNameStr);//注册动态节点-设备名称

                            var toolNameStr = this.realityLineSubData[n].toolNames;
                            this.$set(this.form, nodeId + "_toolName",toolNameStr);//注册动态节点-工具名称

                            var clampNameStr = this.realityLineSubData[n].clampNames;
                            this.$set(this.form, nodeId + "_clampName",clampNameStr);//注册动态节点-夹具名称

                            this.$set(this.form, nodeId+ "_processId", this.realityLineSubData[n].processId);//注册动态节点-当前工序ID
                            if(this.validatenull(this.realityLineSubData[n].deviceClass)){
                                this.$set(this.form, nodeId+ "_deviceClass", this.realityLineSubData[n].deviceClass);//注册动态节点-设备类型
                            }else {
                                this.$set(this.form, nodeId + "_deviceClass", this.realityLineSubData[n].deviceClass.split(","));//注册动态节点-设备类型
                            }
                            if(this.validatenull(this.realityLineSubData[n].material)){
                                this.$set(this.form, nodeId+ "_material", this.realityLineSubData[n].material);//注册动态节点-物料
                            }else {
                                this.$set(this.form, nodeId + "_material", this.realityLineSubData[n].material.split(","));//注册动态节点-物料
                            }
                            if(this.validatenull(this.realityLineSubData[n].auxiliaryMaterial)){
                                this.$set(this.form, nodeId+ "_auxiliaryMaterial", this.realityLineSubData[n].auxiliaryMaterial);//注册动态节点-辅料
                            }else {
                                this.$set(this.form, nodeId + "_auxiliaryMaterial", this.realityLineSubData[n].auxiliaryMaterial.split(","));//注册动态节点-辅料
                            }


                            let obj = new Object();
                            //注册动态节点-各工序作业指导书默认URL
                            if(this.validatenull(this.realityLineSubData[n].workingBook)){
                                this.$set(this.form, nodeId+ "_workingBookFileListPDF",  "#");
                            }else {
                                this.$set(this.form, nodeId + "_workingBookFileListPDF", this.realityLineSubData[n].workingBook);
                                obj.url =this.realityLineSubData[n].workingBook;
                            }
                            //注册动态节点-各工序作业指导书默认名称
                            if(this.validatenull(this.realityLineSubData[n].workingBookName)){
                                this.$set(this.form, nodeId+ "_workingBookFileListPDFName",  null);
                            }else {
                                this.$set(this.form, nodeId + "_workingBookFileListPDFName", this.realityLineSubData[n].workingBookName);
                                obj.name = this.realityLineSubData[n].workingBookName;
                            }

                        }
                        //重新初始化flow组件
                        this.$refs.flow.init();
                        //重置自定义下拉框选项
                        for (var i = 0; i < this.option.nodeList.length; i++) {
                            var nodeId = this.option.nodeList[i].id;
                            var obj = new Object();//创建对象
                            //循环工序属性取出每个工序的个属性数据加入到对象
                            let refDevice = nodeId + "_devicePage";//获取到当前的ref
                            this.$nextTick(() => {
                                this.$refs[refDevice].deviceSelectInit();
                            })
                            let refTool = nodeId + "_toolPage";//获取到当前的ref
                            this.$nextTick(() => {
                                this.$refs[refTool].deviceSelectInit();
                            })
                            let refClamp = nodeId + "_clampPage";//获取到当前的ref
                            this.$nextTick(() => {
                                this.$refs[refClamp].deviceSelectInit();
                            })
                        }
                        console.log(this.form)
                        // console.log(this.option.nodeList)
                        // console.log(this.option.lineList)
                        this.tableLoading = false
                    }).catch(() => {
                        this.tableLoading = false
                    })
                }
            },
            /**获取工厂信息*/
            getFactoryInfo() {
                const factoryId=1;
                getObj(factoryId).then(response => {
                    this.organizationId = response.data.data.menuId;//组织ID
                    this.organizationName = response.data.data.organizationName;//组织名称
                    //获取工厂设备集合
                    this.getFactoryDeviceList();
                })
            },
            /**获取工厂设备集合*/
            getFactoryDeviceList(){
                var obj={
                    position:this.organizationName,//设置组织查询条件
                }
                getDevice(obj).then(response => {
                    this.deviceList = response.data.data;//设备集合
                    for(var i =0; i<this.deviceList.length;i++){
                        if(this.deviceList[i].deviceClass==20){//组织下工具夹具筛选
                            this.clampList.push(this.deviceList[i]);//夹具集合
                            this.toolList.push(this.deviceList[i]);//工具集合
                        }
                    }
                    //重置自定义下拉框选项
                    for (var i = 0; i < this.option.nodeList.length; i++) {
                        var nodeId = this.option.nodeList[i].id;
                        var obj = new Object();//创建对象
                        //循环工序属性取出每个工序的个属性数据加入到对象
                        let refDevice = nodeId + "_devicePage";//获取到当前的ref
                        this.$nextTick(() => {
                            this.$refs[refDevice].deviceSelectInit();
                        })
                        let refTool = nodeId + "_toolPage";//获取到当前的ref
                        this.$nextTick(() => {
                            this.$refs[refTool].deviceSelectInit();
                        })
                        let refClamp = nodeId + "_clampPage";//获取到当前的ref
                        this.$nextTick(() => {
                            this.$refs[refClamp].deviceSelectInit();
                        })
                    }
                })
            },
            /**获取物料集合*/
            getMaterialDataLists(){
                var data={
                    materialType:"0",
                    delFlag:"0"
                }
                getMaterialAccessoryLibraryList(data).then(response => {
                    this.materialDataList=response.data.data;
                })

            },
            /**获取辅料集合*/
            getAuxiliaryMaterialLists(){
                var data={
                    materialType:"1",
                    delFlag:"0"
                }
                getMaterialAccessoryLibraryList(data).then(response => {
                    this.auxiliaryMaterialList=response.data.data;
                })
            },
            /**获取设备分类数据*/
            getDeviceClassListData(){
                getDeviceClassList().then(response => {
                    this.deviceClassList=response.data.data;
                    // console.log(this.deviceClassList)
                })
            },

            /**保存修改实际产线*/
            saveLine(){
                if(this.validatenull(this.realityLineName)){
                    this.$message.warning("请输入产线名称。")
                    return;
                }

                if(this.validatenull(this.articleNumber)){
                    this.$message.warning("品号不能为空。")
                    return;
                }
                if(this.validatenull(this.option.nodeList)){
                    this.$message.warning("产品工艺不能为空")
                    return;
                }

                //组装需要提交的数据-实际产线主表数据组装
                var params = {};//主表参数集合
                params.id = this.lineId;//实际产线ID
                params.realityLineName = this.realityLineName;//实际产线名称
                params.articleNumber = this.articleNumber;//品号
                params.productProcessId = this.productProcessId;//产品工艺ID
                params.organizationName = this.organizationName;//组织名称
                params.organizationId = this.organizationId;//组织ID
                params.productLineType = this.productLineType;//产线类型名称
                params.processNodes = JSON.stringify(this.option.nodeList);//工序节点集合（其中mark字段为工序ID）
                params.processNodeLine = JSON.stringify(this.option.lineList);//工序各节点指向顺序集合

                //组装需要提交的数据-实际产线子表数据组装
                var objArr = [];
                var messageArr=[];
                //循环工序节点集合
                for(var i=0;i<this.option.nodeList.length;i++){
                    var message = new Object();//未选择数据时错误消息对象
                    var error =[];//未选择数据时错误消息集合
                    var obj = new Object();//创建对象

                    if(!this.validatenull(this.form[this.option.nodeList[i].id + '_workshopSection'])) {
                        obj['workshopSection'] = this.form[this.option.nodeList[i].id + '_workshopSection'];
                    }else{
                        obj['workshopSection'] = null;
                        error.push("工段");
                    }


                    if(!this.validatenull(this.form[this.option.nodeList[i].id + '_device'])) {
                        obj['device'] = this.form[this.option.nodeList[i].id + '_device'].toString();
                    }else{
                        obj['device'] = null;
                    }
                    if(!this.validatenull(this.form[this.option.nodeList[i].id + '_tool'])) {
                        obj['tool'] = this.form[this.option.nodeList[i].id + '_tool'].toString();
                    }else{
                        obj['tool'] = null;
                    }
                    if(!this.validatenull(this.form[this.option.nodeList[i].id + '_clamp'])) {
                        obj['clamp'] = this.form[this.option.nodeList[i].id + '_clamp'].toString();
                    }else{
                        obj['clamp'] = null;
                    }
                    if(!this.validatenull(this.form[this.option.nodeList[i].id + '_deviceName'])){
                        obj["deviceNames"] = this.form[this.option.nodeList[i].id + '_deviceName'];
                    }else{
                        obj["deviceNames"] = null;
                    }
                    if(!this.validatenull(this.form[this.option.nodeList[i].id + '_toolName'])){
                        obj["toolNames"] = this.form[this.option.nodeList[i].id + '_toolName'];
                    }else{
                        obj["toolNames"] = null;
                    }
                    if(!this.validatenull(this.form[this.option.nodeList[i].id + '_clampName'])){
                        obj["clampNames"] = this.form[this.option.nodeList[i].id + '_clampName'];
                    }else{
                        obj["clampNames"] = null;
                    }

                    if(!this.validatenull(this.form[this.option.nodeList[i].id + '_auxiliaryMaterial'])) {
                        obj['auxiliaryMaterial'] = this.form[this.option.nodeList[i].id + '_auxiliaryMaterial'].toString();
                    }else{
                        obj['auxiliaryMaterial'] = null;
                    }

                    if(!this.validatenull(this.form[this.option.nodeList[i].id + '_material'])) {
                        obj['material'] = this.form[this.option.nodeList[i].id + '_material'].toString();
                    }else{
                        obj['material'] = null;
                    }

                    if(!this.validatenull(this.form[this.option.nodeList[i].id + '_deviceClass'])) {//设备分类
                        obj['deviceClass'] = this.form[this.option.nodeList[i].id + '_deviceClass'].toString();
                    }else{
                        obj['deviceClass'] = null;
                    }
                    if(error.length>0){
                        message["工序"] = this.option.nodeList[i].name;
                        message["属性"] = error;
                        messageArr.push(message);
                    }
                    obj['processId'] = this.option.nodeList[i].mark;//取出工序ID加入对象
                    obj['processName'] = this.option.nodeList[i].name;//取出工序名称加入对象
                    obj['nodeId'] = this.option.nodeList[i].id;
                    obj['organizationName'] = this.organizationName;//组织名称
                    obj['organizationId'] = this.organizationId;//组织ID
                    obj['lineId'] = this.lineId;//真实产线ID
                    //修改数据数组赋予ID
                    for (var n=0;n< this.realityLineSubData.length;n++){
                        if(this.realityLineSubData[n].nodeId == this.option.nodeList[i].id){
                            obj['id'] = this.realityLineSubData[n].id
                        }
                    }
                    //最后加入提交数据数组
                    objArr.push(obj)
                }
                //漏填提醒
                if(!this.validatenull(messageArr)){
                    this.$message.warning(JSON.stringify(messageArr)+"——等数据未选择。")
                    return;
                }

                //组装需要提交的数据-实际产线设备配置表数据组装
                var deviceArr = [];
                //循环工序节点集合
                for(var i=0;i<this.option.nodeList.length;i++){
                    //循环工序属性取出每个工序的个属性数据加入到对象
                        //将工序属性集合中的属性加入对象同时取出form集合中对应的属性数据放入属性对象中
                    var deviceSnArr = this.form[this.option.nodeList[i].id + '_device'];
                    var deviceNameStr =  this.form[this.option.nodeList[i].id + '__deviceName'];
                    var deviceNameArr = [];
                    if(!this.validatenull(deviceNameStr)) {
                        deviceNameArr =deviceNameStr.split(",");
                    }
                    if(!this.validatenull(deviceSnArr)) {
                        for (var n = 0; n < deviceSnArr.length; n++) {
                            var obj = new Object();//创建对象
                            obj['deviceSn'] = deviceSnArr[n];//设备编码
                            obj['deviceName'] = deviceNameArr[n];//设备名称
                            obj['processId'] = this.option.nodeList[i].mark;//取出工序ID加入对象
                            obj['processName'] = this.option.nodeList[i].name;//取出工序名称加入对象
                            obj['nodeId'] = this.option.nodeList[i].id;
                            obj['organizationName'] = this.organizationName;//组织名称
                            obj['organizationId'] = this.organizationId;//组织ID
                            //最后加入提交数据数组
                            deviceArr.push(obj)
                        }
                    }

                }
                console.log(objArr)
                debugger;
                var data={
                    realityProductLine:params,
                    realityProductLineDetailsList:objArr,
                    realityLineDeviceConfigList:deviceArr,
                    realityLineDeviceConfigListDeleteIds:this.realityLineDeviceConfigListDeleteIds
                }
                //提交
                updateRealityProdictLine(data).then(response => {
                    this.$message.success("修改成功。")
                    var total = response.data.data;
                    //获取实际产线子表数据
                    this.realityLineSubData = total.realityProductLineDetailsList;//实际产线子表数据
                    //实际产线设备配置需要删除的ID集合
                    this.realityLineDeviceConfigListDeleteIds=total.realityLineDeviceConfigListDeleteIds;
                    this.$emit('closeEditReality');//关闭修改页面
                    this.getLogListData();//重新获取操作日志
                });
            },
            handleClick (node) {
                this.$message.success(JSON.stringify(node))
            },
            handleNext () {
                this.count++
                if (this.count >= this.nodeList.length) {
                    this.count = 0;
                }
                this.flowForm = this.nodeList[this.count].id;
            },
            viewShunxu(){
                this.$message.success(JSON.stringify(this.option.lineList))
                /*this.$message.success(JSON.stringify(this.option.nodeList))*/
            },
            handleSelectData(obj){
                this.form[obj.nodeId+"_"+obj.attributeField] = obj.deviceSn;
                this.$set(this.form,obj.nodeId+"_"+obj.attributeField + "Name", obj.deviceName);//注册动态节点-设备名称
                // console.log(this.form)
            },
            refreshChange(){
                getRealityLineDetails(this.lineId).then(response => {
                    //获取产线子表数据
                    this.realityLineSubData = response.data.data;//产线子表数据
                })
            },
            deviceClassChange(nodeId){
                this.$set(this.form, nodeId + "_deviceClass", this.form[nodeId + "_deviceClass"].value);//注册动态节点-设备类型
                this.$set(this.form, nodeId+ "_device", null);//注册动态节点-设备
                this.$set(this.form, nodeId+ "_deviceName", null);//注册动态节点-设备
                let refDevice = nodeId + "_devicePage";//获取到当前的ref
                this.$nextTick(() => {
                    this.$refs[refDevice].deviceSelectInit();
                })
            },
            //打印
            handlePrint () {
                this.$Print('#printDetail');
            },
            //获取产线日志
            getLogListData(){
                getLogList(this.lineId).then(response => {
                    this.logList=response.data.data;
                })
            },
            //作业指导书上传文件选择
            workingBookChange(file, fileList,nodeId){
                var isType=null;
                isType = file.name.substring(file.name.lastIndexOf('.'));
                this.form[nodeId+"_workingBookFileList"] = fileList.slice(-1);
                if(isType === '.pdf'){
                    file.url = URL.createObjectURL(file.raw);//创建上传文件URL
                    // this.form[nodeId+"_workingBookFileListPDF"]=file.url;
                    // this.form[nodeId+"_workingBookFileListPDFName"]=file.name;
                    //将需要上传的作业指导书存入集合
                    file.raw.node = nodeId;//设置作业指导书所属工序顺序方便上传后保存对应工序
                    this.workList[nodeId+"work"] = file;
                    var id;
                    for(var n=0;n<this.realityLineSubData.length;n++) {
                        debugger;
                        if(this.realityLineSubData[n].nodeId == nodeId){
                            id= this.realityLineSubData[n].id;
                        }
                    }
                    var fileData = new FormData();
                    fileData.append("id", id);
                    fileData.append('file[]',file.raw);
                    uploadSubmit(fileData).then(response => {
                        this.$message({
                            message: "上传成功了",
                            type: 'success'
                        });
                        var workingBook = response.data.data.workingBook;
                        var workingBookName = response.data.data.workingBookName;
                        if (workingBook != "" && workingBook != null) {
                            this.$set(this.form, nodeId + "_workingBookFileListPDF", workingBook);
                            this.$set(this.form, nodeId + "_workingBookFileListPDFName", workingBookName);
                        }
                    }).catch(response => {
                        this.$message({
                            message: "上传失败了",
                            type: 'error'
                        });
                        this.$set(this.form, nodeId+ "_workingBookFileListPDF",  "#");
                        this.$set(this.form, nodeId+ "_workingBookFileListPDFName", null);
                    })



                }
                isType = file.raw.type==='application/pdf';
                if (!isType) {
                    this.$notify.warning({
                        title: '警告',
                        message: '请上传格式为application/pdf格式的作业指导书文件。'
                    })
                }

                const isLt = file.size / 1024 / 1024 < 10;
                if (!isLt) {
                    this.$notify.warning({
                        title: '警告',
                        message: '上传作业指导书文件大小不能超过 10MB!'
                    })
                }
                return isType && isLt;
            },
            //作业指导书文件删除
            deleteWorkingBook(nodeId){
                var id;
                for(var n=0;n<this.realityLineSubData.length;n++) {
                    if(this.realityLineSubData[n].nodeId == nodeId){
                        id= this.realityLineSubData[n].id
                    }
                }
                var formdata = new FormData();
                formdata.append("id", id);
                deletWorkBook(formdata).then(response => {
                    this.$message({
                        message: "删除成功",
                        type: 'success'
                    });
                    this.form[nodeId+"_workingBookFileListPDF"]="#";//各工序作业指导书默认URL
                    this.form[nodeId+"_workingBookFileListPDFName"]=null;//各工序作业指导书默认名称
                    this.form[nodeId+"_workingBookFileList"]=[];//各工序控制作业指导书列表上传前可以切换文件
                    this.$delete(this.workList, nodeId+"work");//同时清空作业指导书上传集合
                }).catch(response => {
                    this.$message({
                        message: "删除失败",
                        type: 'error'
                    });
                })

            },

        }
    };
</script>

<style scoped>
  /deep/.avue-flow__node{
    height: auto!important;
  }
  /deep/ .avue-flow__node-header {
    line-height: 30px;
  }
  /deep/.el-descriptions__title {
    font-size: 14px;
    font-weight: 400;
    margin-top: 5px;
  }

  /*以下样式是打印的时候avue表格错乱修正方式（主要是序号列和操作列固定影响的）*/
  /deep/.el-table__fixed{
    display: none!important;
  }
  /deep/.el-table__fixed-right{
    display: none!important;
  }
  /deep/.el-table__cell.is-hidden>*{visibility:visible !important;}

  /deep/ .avue-grid{
    display: none!important;
  }
  /deep/.el-main{
    background:#efefef !important;
  }
  /deep/.el-card__body{
    padding: 0px!important;
  }
  /*去掉滚动条样式*/
  .demo::-webkit-scrollbar {
    display: none; /* Chrome Safari */
  }
  .demo {
    scrollbar-width: none; /* firefox */
    -ms-overflow-style: none; /* IE 10+ */
    overflow-x: hidden;
    overflow-y: auto;
  }

</style>
